package com.pxl.springbootinit.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.pxl.springbootinit.common.BaseResponse;
import com.pxl.springbootinit.common.ErrorCode;
import com.pxl.springbootinit.common.ResultUtils;
import com.pxl.springbootinit.exception.BusinessException;
import com.pxl.springbootinit.model.dto.task.UserFeedbackForm;
import com.pxl.springbootinit.model.vo.UserFeedbackVO;
import com.pxl.springbootinit.service.UserFeedbackService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 用户反馈接口
 *
 * @author MADAO
 * @create 2024 - 12 - 23 10:23
 */
@RestController
@RequestMapping("/userFeedback")
public class UserFeedbackController {

    @Resource
    private UserFeedbackService userFeedbackService;

    /**
     * 创建用户反馈
     * @param userFeedbackForm
     * @return
     */
    @PostMapping("/create")
    public BaseResponse<Boolean> createUserFeedback(@RequestBody UserFeedbackForm userFeedbackForm) {
        return ResultUtils.success(userFeedbackService.createUserFeedback(userFeedbackForm));
    }

    @PostMapping("/remove/{id}")
    public BaseResponse<Boolean> removeUserFeedbackById(@PathVariable Long id) {
        if (id == null){
            throw new BusinessException(ErrorCode.PARAMS_ERROR);
        }
        return ResultUtils.success(userFeedbackService.removeById(id));
    }

    @PostMapping("/update")
    public BaseResponse<Boolean> updateUserFeedback(@RequestBody UserFeedbackForm userFeedbackForm) {
        return ResultUtils.success(userFeedbackService.updateUserFeedback(userFeedbackForm));
    }

    @GetMapping("/page")
    public BaseResponse<Page<UserFeedbackVO>> pageUserFeedback(UserFeedbackForm userFeedbackForm) {
        return ResultUtils.success(userFeedbackService.pageUserFeedback(userFeedbackForm));
    }

    //region
    @PostMapping("/answer")
    public BaseResponse<Boolean> answerUserFeedback(@RequestBody UserFeedbackForm userFeedbackForm) {
        return ResultUtils.success(userFeedbackService.answerUserFeedback(userFeedbackForm));
    }
    @GetMapping("/admin/page")
    public BaseResponse<Page<UserFeedbackVO>> pageAdminUserFeedback(UserFeedbackForm userFeedbackForm) {
        return ResultUtils.success(userFeedbackService.pageAdminUserFeedback(userFeedbackForm));
    }
    //endregion
}
